<?php
class CMRPageViewViewHistory extends CMRPage
{
	protected function getContentsDiv()
	{
		$html = "<div id=\"content\">\n";
		$html .= "<h1>View History</h1>";

		$sectionsPanel = new SectionsPanel('');
		$html .= $sectionsPanel->getHTML();
		
		$shortcutPanel = new ShortcutPanel('');
		$html .= $shortcutPanel->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("ViewNext20End");
		$hidden->setValue('20');
		$html .= $hidden->getHTML();
		
		$hidden = new Hidden();
		$hidden->setName("ResourceID");
		$html .= $hidden->getHTML();
		
		$overrideDivAction = new Hidden();
		$overrideDivAction->setName("OverrideDivAction");
		$overrideDivAction->setValue("False");
		$html .= $overrideDivAction->getHTML();

		$html .= "<div id=\"viewlist\">\n";
		$html .= "<table>\n";

		$sql = "SELECT * from ViewedResources ORDER BY ViewedWhen DESC LIMIT 20";
		$this->Database->ExecuteSQL($sql);
		while($row=$this->Database->getRow())
		{
			$database1 = $this->Database->recopy();

			$resource = new Resource($this->Database,$row['ResourceID']);
			
			// get user
			$sql1 = "SELECT LongName from Users where UserID = ".$row['UserID'];
			$database1->ExecuteSQL($sql1);
			$row2 = $database1->getRow();
//			print_r($row2);
			
			$date = new DateTime($row['ViewedWhen']);
			
			$filename = "";
			if ($row['PhysicalFileNumber']!=0)
				{
					// get filename
					$database2 = $this->Database->recopy();
					$sql2 = "SELECT FSFileName from Files where PhysicalFileNumber = ".$row['PhysicalFileNumber'];
					$database2->ExecuteSQL($sql2);
					$row3=$database2->getRow();
					$filename = " (".$row3['FSFileName'].") ";
				}
			
			$html .= "<tr><td style=\"width:140px;\">".
				$date->format("D j M Y H:i")."</td><td style=\"width:100px;\">".
				$row2['LongName']."</td><td style=\"width:250px;\">".
//				$row1['LongName']."</td><td style=\"width:250px;\">".
				"<a href=\"javascript:OnClickSummary('".$resource->getResourceID()."');\">".
				"(".$resource->getResourceID().") ".
				$resource->getResourceTitle().$filename."</a></td></tr>\n";
		}
	
		$html .= "</table>\n";
		$html .= "</div>\n"; // end of actionlist

		$button = new JavascriptButton();
		$button->setName("ViewNext20Button");
		$button->setJavaScript("ViewNext20();");
		$button->setValue("Next 20");
		$html .= "<p style=\"text-align:center;\">".$button->getHTML()."<p>\n";
		
	
		$html .= "</div>\n"; // end of content
		return $html;
	}
}
				

?>